package Utils

import (
	"os"
	"os/exec"
	"path"
	"path/filepath"
	"strings"
)

func GetCurrentPath() string {
	_path, err := exec.LookPath(os.Args[0])
	CheckErr(err)
	return _path
}

func _GetDir(_path string) string {
	i := strings.LastIndex(_path, Separator())
	ret := string(_path[0 : i+1])
	return ret
}

func GetStartDir() string {
	_path, err := os.Getwd()
	CheckErr(err)
	return _path + Separator()
}

func Separator() string{
	return string(filepath.Separator)
}

func AddPathSeparator(p string) string{
	if p[len(p):] == Separator(){
		return p
	}
	return p + Separator()
}

func GetFileNameExt(p string) string {
	return path.Ext(p)
}

func GetFileName(p string) string {
	_, filename := GetDirAndFileName(p)
	return filename
}

func GetDir(p string) string{
	dir, _ := GetDirAndFileName(p)
	return dir
}

func GetDirAndFileName(p string) (string, string)  {
	return filepath.Split(p)
}

func GetFileNameNotExt(p string) string{
	fname := GetFileName(p)
	ext := GetFileNameExt(fname)
	return strings.Trim(fname, ext)
}

